package com.java.dao.impl;

import com.java.dao.OrderDetailDao;
import com.java.domain.OrderDetail;
import com.java.utils.DruidUtils;
import org.apache.commons.dbutils.QueryRunner;

import java.sql.SQLException;

/**
 * @version 2020.3.4
 * @User 悠恋
 * @Data 2022/11/26
 * @Time 18:33
 */
public class OrderDetailDaoImpl implements OrderDetailDao {
    private QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());
    String sql = "";

    // 订单详情
    @Override
    public int addOrderDetail(OrderDetail orderDetail) {
        try {
            sql = "insert into orderdetail values (?,?,?,?,?,?,?)";
            // 准备参数
            Object[] param = {orderDetail.getOdid(), orderDetail.getGname(), orderDetail.getGprice()
                    , orderDetail.getGtotal(), orderDetail.getNum(), orderDetail.getGimg(), orderDetail.getOid()};

            // 执行SQL返回结果
            return qr.update(sql, param);
        } catch (SQLException e) {
            e.printStackTrace();
            return 0;
        }

    }
}
